package com.longsys.framework.eventsourcing.sbclient.kafka;

import com.longsys.eventsourcing.core.EventAggregate;
import com.longsys.framework.eventsourcing.sbclient.core.EventAggregateMsgProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;

/**
 * @author guozhu.huang
 * @date 2021/9/17 14:00
 */
@Slf4j
public class KafkaEventAggregateMsgProducer implements EventAggregateMsgProducer {

    private KafkaTemplate<String, EventAggregate> kafkaTemplate;
    private String topic;

    public KafkaEventAggregateMsgProducer(KafkaTemplate<String, EventAggregate> kafkaTemplate, String topic) {
        this.kafkaTemplate = kafkaTemplate;
        this.topic = topic;
    }

    @Override
    public void send(EventAggregate eventAggregate) {
        kafkaTemplate.send(topic, eventAggregate);
    }

}
